#!env ruby

def composed( word, words )
  (1..word.length()-1).each do |i|
    pre = word[0,i]
    post = word[i,word.length()-1]
    if ( words.include?(pre) and 
         ( words.include?(post) or
           composed( post, words ) ))
      return true
    end
  end
  return false
end

require 'Set'
wordset = Set.new
ARGF.each do |line|
  wordset.add(line.strip)
end

# Seems it is faster to iterate an array than a Set. Same seemed to be
# true in python.
result = ""
wordset.to_a().each do |word|
  if word.length() > result.length()
    if ( composed( word, wordset ) )
      result = word
    end
  end
end

print result.length," ",result,"\n"
